# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/22'
__author__ = 'Just'
__filename__ = 'banner'
"""
from datetime import datetime
from app.model.base import MixinJSONSerializer


class BannerViewModel(MixinJSONSerializer):
    """单个主题详细信息"""
    def __init__(self, banner, items):
        self.id = banner.id
        self.name = banner.name
        self.description = banner.description
        self.update_time = datetime.fromtimestamp(banner.update_time)
        self.count = len(items)
        self.items = items
        self._fields = ['id', 'name', 'description', 'update_time', 'count', 'items']


class BannerCollection(MixinJSONSerializer):
    """一组Banner"""
    def __init__(self):
        self.total = None
        self.banners = []
        self._fields = ['banners', 'total']

    def fill(self, collection):
        """
        一组list对象
        :param collection: zip包装list banner对象
        """
        self.banners = [BannerViewModel(item[0], item[1]) for item in collection]
        self.total = len(self.banners)
